//InnerAudioContext实例
const app = getApp()

 
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    pic_num:521,
    go_num : '2,1 A',
    left_num : '2,0 D',
    right_num :'2,0 B',
    id:'',
    animationMain:null,
    fshow:1,
    huo1:1,
    huo2:0,
    huo3:0,
    huo4:0,
    huo5:0,
    huo6:0,
    huo7:0,
    huo8:0,
    huo9:0,
    huo10:0,
    huo11:0,
  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },
 
  //播放按钮事件
  playLeft : function(){
    let lnum = this.data.huo1;
    lnum++;
    this.setData({
      huo1:lnum
    })
    // wx.showModal({
    //   title: '提示',
    //   content: "本攻略将于近期开放，敬请期待。"
    // })
  },
 
  //停止按钮事件
  playRight : function(){
    let rnum = this.data.right_num;
    this.setData({
      huo1:1
    })
    // wx.showModal({
    //   title: '提示',
    //   content: "本攻略将于近期开放，敬请期待。"
    // })

  },
 
  //进度条改变后触发事件
  doorChange : function(go_num){
    var that = this;
    var id = this.data.id;
    var gonum = go_num.replace(' ','').replace(',','');
    var ret = wx.getStorageSync("doordata"+gonum) || null;
    console.log('get data===id='+id+' go_num='+gonum+JSON.stringify(ret))

    if(ret){
      if(ret != null && gonum != ''){
        console.log('no null');
        // that.setData({
        //   go_num: ret.forward_door,
        //   left_num: ret.left_door,
        //   right_num: ret.right_door,
        //   pic_num:ret.num,
        //   id:ret.id,
        // })
        that.timeUpdate(go_num);
      }
      else{
        console.log('no data2')
        that.timeUpdate(go_num);
      }
    }
    else{
      console.log('no data3')
      that.timeUpdate(go_num);
      //ret = wx.getStorageSync("doordata"+gonum);
    }
    //ret = wx.getStorageSync("doordata"+gonum);
    
    
    //this.playMusic();
    
  },
  //进度条拖动过程中触发事件
  playReset : function(e){
    
    this.setData({
      pic_num:521,
      go_num : '2,1 A',
      left_num : '2,0 D',
      right_num :'2,0 B',
      id:'',
    });
    //this.timeUpdate('2,1 A','521');
    //wx.removeStorageSync("doordata"+pic_num);

  },
 
  //将秒钟转化为mm：ss的时间格式
  musicTimeFormat : function(time){
    var second = Math.floor(time % 60);
    if(second<10){
      second = '0' + second;
    }
    var minute = Math.floor(time / 60);
    if (minute < 10) {
      minute = '0' + minute;
    }
    return minute + ':' + second;
  },
 
  //播放的时候，更新进度条和时间显示
  timeUpdate : function(go_num){
    var that = this;
    wx.request({
      url: app.globalData.publicAdress + '/api/game/doorinfo',
      method: "post",
      header: {
        'content-type': 'application/json', // 默认值
        'Accept': 'application/vnd.cowsms.v2+json',
        'Authorization': 'Bearer ' + wx.getStorageSync("token"),
      },
      data: {
        name: go_num,
      },
      success: function (res) {
        //wx.hideLoading()
        //console.log(JSON.stringify(res))
        //如果token失效   则返回新的token  
        if (res.header.Authorization) {
          var str = res.header.Authorization;
          // console.log(str)
          wx.removeStorageSync("token");
          wx.setStorageSync("token", str.substring(7, str.length))
        }
        if (res.statusCode == '200') {
          // that.setData({
          //   answerList: res.data.data, //评论列表
          // })
          if(res.data.data != null){
            var ret = res.data.data;
            console.log('ret==='+JSON.stringify(ret));
            var id = ret.id;
            var gonum = go_num.replace(' ','').replace(',','');
            wx.setStorageSync("doordata"+gonum,ret);
            wx.setStorage({
              key:"doordata"+gonum,
              data:ret
            });
            
            that.setData({
              go_num: ret.forward_door,
              left_num: ret.left_door,
              right_num: ret.right_door,
              pic_num:ret.num,
              id:ret.id,
            })

            //console.log('new datalist==='+JSON.stringify(datalist));
          }else{
            wx.showModal({
              title: '提示',
              content: '门锁了？',
              success: (res) => {
                  // wx.switchTab({
                  //   url: '/pages/strategyList/strategyList'
                  // })                
              }
            })
          }
        }
      }
    })


    
  },
  leifent_rotate_click_left: function(per,isload) {
    var that = this
       //canOnePointMove = false;
       //console.log(e.currentTarget)
       //var top = 0,stop = 0;
      //  const query = this.createSelectorQuery()
      //  query.select('#leifengta').boundingClientRect()
      //  query.selectViewport().scrollOffset()
      //  query.exec(function (res) {
      //    //console.log(res)
      //    var top = 0,stop = 0,left=0,rotate=that.data.leifengta_rotate+3.6;
      //    //rotate = rotate*per;
      //    console.log('rotate==='+rotate);
      //    top = res[0].top // #the-id节点的上边界坐标
      //    left = res[0].left
      //    stop = res[1].scrollTop // 显示区域的竖直滚动位置
      //    that.setData({
      //      msg: '旋转1  top='+top + ' left='+left,
      //      leifengta_top:top,
      //      leifengta_left:left,
      //      leifengta_rotate:rotate,
      //    })
      //    console.log('旋转1  top='+top + ' left='+left);
      //  })
      //var rotate=that.data.leifengta_rotate+10.8;
      var rotate=that.data.leifengta_rotate+10.8;
      var rotate2 = that.data.changzhen_rotate+0.2;
      if(isload==1){
        rotate = 10.8*per;
        rotate2 = 0.2*per+45;
      }
 
      
         console.log('rotate==='+rotate);

         that.setData({
           leifengta_rotate:rotate,
           changzhen_rotate:rotate2,
         })
         //console.log('旋转1  top='+top + ' left='+left);
       //this.data.leifengta_rotate++;
       //that.rotateAni(++this.data.leifengta_rotate);
    },
      /**
 * 实现image旋转动画，每次旋转 45*n度
 */

})